from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from options import options
from time import sleep


#打开的页面，句柄还在第一个
driver= webdriver.Chrome(options=options)
driver.get(r'http://www.baidu.com')
driver.maximize_window()
driver.implicitly_wait(20)

title=driver.title
print(title)
driver.find_element(By.LINK_TEXT,'hao123').click()
title2=driver.title
print(title2)
driver.find_element(By.LINK_TEXT,'新闻').click()
sleep(2)
title3=driver.title
print(title3)
hao123_handle = driver.window_handles[2]
news_handle = driver.window_handles[1]

'''
打开新页面的顺序 0 1 2 3 4
句柄的顺序      0 4 3 2 1
'''
driver.switch_to.window(news_handle)
title4=driver.title
print(title4)
driver.switch_to.window(hao123_handle)
title5=driver.title
print(title5)